//题目:给出一个人32位的有符号整数
//例如输入: 123 输出: 321 输入: -123 输出: -321 输入120 输入 21
//注意点 需要判断临界值溢出 取值范围为[−2(31),  2(31) − 1] 如果溢出 那么返回0
//let n(m) = Math.pow(n,m);
//题解:假设范围为-2(9)~2(9)-1 即-512~511
//let x = 125
//倒转则为521>511溢出
//let x = 315
//倒转为513
//let re = parseInt(513/10)=51
//let pop = 513%10 = 3
//因为re == 511/10 并且 pop >511%10 所以溢出

var reverse = function (x) {
    var re = 0;
    while (parseInt(x / 10)) {
        re = 10 * re + x - 10 * parseInt(x / 10);
        x = parseInt(x / 10);
    }
    if (re > 214748364 || re < -214748364) return 0;
    if ((re == 214748364 && x > 7) || (re == -214748364 && x < -8)) return 0;
    re = 10 * re + x;
    return re
};
console.log(Math.pow(2,31)-1)
console.log(reverse(-2147483641))
console.log(parseInt(513/10))

